<?php

/**
 * LEAGUEMan
 *
 * Copyright (C) 2007 Marko Bischof
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

$database = $this->project->getDB();

?>

<div class="contentheading">
    <?php echo $this->project->getName();?>
</div>

{tab=<?php echo $this->round->getName();?>}
{leagueman_roundresult p="<?php echo $this->project->getID();?>" r="<?php echo $this->round->getOrdering();?>"}

{tab=<?php echo _LM_TABLE;?>}
{leagueman_leaguetable p="<?php echo $this->project->getID();?>" r="<?php echo $this->round->getOrdering();?>"}

{tab=<?php echo _LM_INFO;?>}
<table class="contentpaneopen">
    <tr>
        <td width="50%" class="sectiontableheader">General</td>
        <td width="50%" class="sectiontableheader">Goals</td>
    </tr>
    <tr>
        <td valign="top">
            <table width="100%">
                <tr>
                    <td>Total Rounds:</td>
                    <td><?php echo $this->info->getMaxRound();?></td>
                </tr>
                <tr>
                    <td>Current Round:</td>
                    <td><?php echo $this->info->getCurrentRound();?></td>
                </tr>
                <tr>
                    <td>Total Matches:</td>
                    <td><?php echo $this->info->getTotalMatches();?></td>
                </tr>
                <tr>
                    <td>Matches played:</td>
                    <td><?php echo $this->info->getCountMatchesPlayed();?></td>
                </tr>
                <tr>
                    <td><b>Highest Home Win:</b></td>
                </tr>
                <tr>
                    <td>
                        <?php foreach($this->info->getHighestHomeWins() AS $row):?>
                            <?php if($row->match_result_0_1 != null && $row->match_result_0_2 != null):?>
                                <?php printf("%s - %s %s:%s<br/>", $row->team1, $row->team2, $row->match_result_0_1, $row->match_result_0_2);?>
                            <?php endif;?>
                        <?php endforeach;?>
                    </td>
                </tr>
                <tr>
                    <td colspan="2"><b>Highest Away Win:</b></td>
                </tr>
                <tr>
                    <td>
                        <?php foreach($this->info->getHighestAwayWins() AS $row):?>
                            <?php if($row->match_result_0_1 != null && $row->match_result_0_2 != null):?>
                                <?php printf("%s - %s %s:%s<br/>", $row->team1, $row->team2, $row->match_result_0_1, $row->match_result_0_2);?>
                            <?php endif;?>
                        <?php endforeach;?>
                    </td>
                </tr>
            </table>
        </td>
        <td valign="top">
            <table width="100%">
                <tr>
                    <td><b>Total Goals:</b></td>
                    <td><?php echo $this->info->getTotalGoals();?></td>
                </tr>
                <tr>
                    <td>&nbsp;&#216; Goals per Round:</td>
                    <td><?php echo $this->info->getTotalGoalsPerRound();?></td>
                </tr>
                <tr>
                    <td>&nbsp;&#216; Goals per Match:</td>
                    <td><?php echo $this->info->getTotalGoalsPerMatch();?></td>
                </tr>

                <tr>
                    <td><b>Total Goals Home:</b></td>
                    <td><?php echo $this->info->getTotalHomeGoals();?></td>
                </tr>
                <tr>
                    <td>&nbsp;&#216; Goals Home per Round:</td>
                    <td><?php echo $this->info->getTotalHomeGoalsPerRound();?></td>
                </tr>
                <tr>
                    <td>&nbsp;&#216; Goals Home per Match:</td>
                    <td><?php echo $this->info->getTotalHomeGoalsPerMatch();?></td>
                </tr>

                <tr>
                    <td><b>Total Goals Away:</b></td>
                    <td><?php echo $this->info->getTotalAwayGoals();?></td>
                </tr>
                <tr>
                    <td>&nbsp;&#216; Goals Away per Round:</td>
                    <td><?php echo $this->info->getTotalAwayGoalsPerRound();?></td>
                </tr>
                <tr>
                    <td>&nbsp;&#216; Goals Away per Match:</td>
                    <td><?php echo $this->info->getTotalAwayGoalsPerMatch();?></td>
                </tr>
            </table>
        </td>
    </tr>
</table>

{tab=Special}
<?php $rows = $this->info->getLatestForumPosts(20);?>
<?php $fItemid = $this->info->getForumItemid();?>

<table class="contentpane">
    <tr>
        <td class="sectiontableheader" width="200"><?php echo 'Title';?></td>
        <td class="sectiontableheader" align="center"><?php echo 'Posts';?></td>
        <td class="sectiontableheader"><?php echo 'Author';?></td>
        <td class="sectiontableheader"><?php echo 'Datetime';?></td>
    </tr>

    <?php

    if(count($rows) > 0) {

        foreach($rows as $row) {

            $database->setQuery("SELECT MAX(time) FROM jos_sb_messages WHERE thread = " . $row->thread);
            $latestPostTime		= $database->loadResult();

            $result = "";
            $database->setQuery(
                    "SELECT a.id, a.name, a.catid, b.name AS catname
						   FROM jos_sb_messages AS a
					  LEFT JOIN jos_sb_categories AS b ON a.catid = b.id
						  WHERE a.time = $latestPostTime AND a.thread = " . $row->thread
            );
            $database->loadObject($result);

            $latestPostId		= $result->id;
            $latestPostName		= $result->name;
            $latestPostCatid	= $result->catid;
            $catname			= $result->catname;

            $database->setQuery(
                    "SELECT COUNT(0) FROM jos_sb_messages WHERE thread = " . $row->thread
            );
            $numberOfPosts = $database->loadResult();

            ?>

    <tr class="<?php $this->plugin("toggle", "sectiontableentry1", "sectiontableentry2")?>">
        <td  width="200">
            <a href="<?php echo sefRelToAbs('index.php?option=com_jbulletin&amp;Itemid=' . $fItemid . '&amp;func=view&amp;catid=' . $latestPostCatid . '&amp;id=' . $row->thread) . '#msg' . $latestPostId;?>">
                        <?php echo htmlspecialchars(stripslashes($row->subject));?>
            </a>
            <br />
        </td>
        <td align="center"><?php echo $numberOfPosts; ?></td>
        <td><?php echo htmlspecialchars($latestPostName); ?></td>
        <td><?php echo date("F j, Y, G:i", $latestPostTime); ?></td>
    </tr>

            <?php
        }

    } else { ?>

    <tr>
        <td><?php echo "";?></td>
    </tr>

        <?php
    }

    ?>

</table>

{tab=Clubs}
<?php include $this->loadTemplate("clublist.tpl.php")?>

{/tabs}